package com.ilovetolearn.business
{
	import com.adobe.cairngorm.business.ServiceLocator;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.serialization.json.JSON;
	import com.ilovetolearn.event.SaveWordEvent;
	import com.ilovetolearn.vo.SaveDataVo;

	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;

	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.http.HTTPService;

	public class SaveDataDelegate implements IResponder
	{
		private var _responder:IResponder;
		private var _httpservice:HTTPService;

		public function SaveDataDelegate(responder:IResponder)
		{
			this._responder=responder;
			this._httpservice=ServiceLocator.getInstance().getHTTPService("savehs");
		}

		public function saveData(vo:SaveDataVo):void
		{
			this._httpservice.url+=vo.toParamString();
			this._httpservice.method=URLRequestMethod.POST;
//			var variables:URLVariables=new URLVariables();
//			variables.uid=vo.uid;
//			variables["do"]="saveword";
//			variables.courseid=vo.courseid;
//			variables.data=JSON.encode(vo.data);
			this._httpservice.request.data=JSON.encode(vo.data.toArray());
			trace("保存数据：" + this._httpservice.request.data);
			this._httpservice.contentType="application/x-www-form-urlencoded";
			var token:AsyncToken=this._httpservice.send();
			token.addResponder(this);
		}

		public function result(data:Object):void
		{
			_responder.result(data);
		}

		public function fault(info:Object):void
		{
			_responder.fault(info);
		}
	}
}